home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / ppm / qrttoppm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-10  |  1.8 KB  |  69 lines

  1. /* qrttoppm.c - read a QRT ray-tracer output file and produce a portable pixmap
  2. **
  3. ** Copyright (C) 1989 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include "ppm.h"
  14.  
  15. void
  16. main( argc, argv )
  17.     int argc;
  18.     char* argv[];
  19.     {
  20.     FILE* ifp;
  21.     register pixel* pixelrow;
  22.     int rows, cols, row, col;
  23.     pixval maxval;
  24.     unsigned char* buf;
  25.  
  26.     ppm_init( &argc, argv );
  27.  
  28.     if ( argc > 2 )
  29.     pm_usage( "[qrtfile]" );
  30.  
  31.     if ( argc == 2 )
  32.     ifp = pm_openr( argv[1] );
  33.     else
  34.     ifp = stdin;
  35.  
  36.     /* Read in the QRT file.  First the header. */
  37.     cols = getc( ifp );
  38.     cols += getc( ifp ) << 8;
  39.     rows = getc( ifp );
  40.     rows += getc( ifp ) << 8;
  41.  
  42.     if ( cols <= 0 || rows <= 0 )
  43.     pm_error( "invalid size: %d %d", cols, rows );
  44.     maxval = 255;
  45.  
  46.     ppm_writeppminit( stdout, cols, rows, maxval, 0 );
  47.     pixelrow = ppm_allocrow( cols );
  48.     buf = (unsigned char *) malloc( 3 * cols );
  49.     if ( buf == (unsigned char *) 0 )
  50.     pm_error( "out of memory" );
  51.  
  52.     for ( row = 0; row < rows; row++ )
  53.     {
  54.         (void) getc( ifp );    /* discard */
  55.         (void) getc( ifp );    /* linenum */
  56.     if ( fread( buf, 3 * cols, 1, ifp ) != 1 )
  57.         pm_error( "EOF / read error" );
  58.     for ( col = 0; col < cols; col++ )
  59.         PPM_ASSIGN(
  60.         pixelrow[col], buf[col], buf[cols + col], buf[2 * cols + col] );
  61.     ppm_writeppmrow( stdout, pixelrow, cols, maxval, 0 );
  62.     }
  63.  
  64.     pm_close( ifp );
  65.     pm_close( stdout );
  66.  
  67.     exit( 0 );
  68.     }
  69.